package com.luoc.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

public class JdbcDemo {
    public static void main(String[] args) throws  Exception {
        //连接数据库
        String url = "jdbc:mysql://localhost:3306/luoc";
        String name = "root";
        String password = "123456";
        Connection connection = DriverManager.getConnection(url, name, password);
        //执行sql语句
        PreparedStatement preparedStatement = connection.prepareStatement("insert into user (name,age) value (?,?)");
        preparedStatement.setString(1,"小梅");
        preparedStatement.setInt(2,21);

        int i = preparedStatement.executeUpdate();
        if(i > 0 ){
            System.out.println("执行成功！");
        }
        else{
            System.out.println("执行失败！");
        }
        //关闭连接
        preparedStatement.close();
    }



















}
